<?php
namespace Modules\Order\Http\Controllers\Admin\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use Modules\Order\Entities\ProductOrder as Order;
use Modules\Order\Entities\Aftersale;

use Validator;
use ThrowException;
use Auth;
use Setting;

class AftersaleController extends Controller
{
    public function show(Request $req, $uuid)
    {
        $aftersale = Aftersale::getEntity([
            'uuid' => $uuid
        ]);

        $info = $aftersale->getInfo();

        return [
            'info' => $info
        ];
    }

    public function update(Request $req, $uuid)
    {
        $rule = [
            'type' => ['required'],
        ];

        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        // 订单
        $aftersale = Aftersale::getEntity([
            'uuid' => $uuid
        ]);

        $type = $req->type;

        // 更新寄回信息
        if ($type === 'reject') {
            $info = $req->all();
            $aftersale->reject($info);
        }
        elseif ($type === 'accept') {
            $info = $req->all();
            $aftersale->accept($info);
        }
        elseif ($type === 'complete') {
            $aftersale->complete();
        }
        elseif ($type === 'close') {
            // $aftersale->closeByUser();
        }

        return [];
    }
}
